package org.hawk.gwt.ppc.scanner.utils;

import java.util.List;
/**
 * Represents type scope with generic arguments.
 * See subclasses for specific explanations.
 * 
 * @author alex.bereznevatiy@gmail.com
 *
 */
public abstract class JavaGenericTypeScope extends JavaTypeScope {
	
	private JavaTypeScope type;
	private JavaNameResolver owner;

	JavaGenericTypeScope(JavaTypeScope type, JavaNameResolver owner) {
		super(type.getParent(), type.getStart(), type.getFields(), type.loader);
		this.type = type;
		this.owner = owner;
		endScope(type.getEnd());
	}
	
	@Override
	public JavaNameResolver getOwner() {
		return owner;
	}
	
	@Override
	public List<JavaScope> getChildren() {
		return type.getChildren();
	}

	@Override
	public List<JavaModifier> getModifiers() {
		return type.getModifiers();
	}

	@Override
	public String getClassName() {
		return type.getClassName();
	}

	@Override
	public String getResolvedClassName() {
		return type.getResolvedClassName();
	}

	@Override
	public String getEntityType() {
		return type.getEntityType();
	}

	@Override
	public List<JavaTypeScope> getImplementedInterfaces() {
		return type.getImplementedInterfaces();
	}

	@Override
	public List<JavaVariable> getFields() {
		return type.getFields();
	}

	@Override
	public List<JavaConstructor> getDeclaredConstructors() {
		return type.getDeclaredConstructors();
	}

	@Override
	public List<JavaTypeVariable> getTypeVariables() {
		return type.getTypeVariables();
	}

	@Override
	public JavaClassDescriptor resolveTypeDescriptor(String typeName) {
		return owner.resolveTypeDescriptor(typeName);
	}

	@Override
	public JavaTypeScope getSuperClass() {
		return type.getSuperClass();
	}

	@Override
	public JavaGenericTypeScope getGenericSuperclass() {
		return type.getGenericSuperclass();
	}

	@Override
	public String resolveType(String typeSimpleName) {
		return owner.resolveType(typeSimpleName);
	}

	@Override
	public String toString() {
		return type.toString();
	}

	/*
	 * TODO: check type parameters when calling this method
	 * (non-Javadoc)
	 * @see org.hawk.gwt.ppc.scanner.utils.JavaTypeScope#isAssignableFrom(org.hawk.gwt.ppc.scanner.utils.JavaTypeScope)
	 */
	@Override
	public boolean isAssignableFrom(JavaTypeScope type) {
		if (type instanceof JavaGenericTypeScope) {
			type = ((JavaGenericTypeScope)type).type;
		}
		return this.type.isAssignableFrom(type);
	}
}
